		var map = new BMap.Map('map_canvas');
		map.centerAndZoom(new BMap.Point(116.404, 39.915), 13);
		var lushu;
		var myIcon = new BMap.Icon(
				"http://api.map.baidu.com/lbsapi/cloud/cms/Mario.png", {
					width : 128,
					height : 128
				}, {
					anchor : new BMap.Size(65, 128)
				});
		// 实例化一个驾车导航用来生成路线
		var drv = new BMap.DrivingRoute(
				'北京',
				{
					onSearchComplete : function(res) {
						if (drv.getStatus() == BMAP_STATUS_SUCCESS) {
							var arrPois = res.getPlan(0).getRoute(0).getPath();
							map.addOverlay(new BMap.Polyline(arrPois, {
								strokeColor : '#111'
							}));
							map.setViewport(arrPois);

							lushu = new BMapLib.LuShu(
									map,
									arrPois,
									{
										defaultContent : "从天安门到天坛公园",
										speed : 450,
										icon : myIcon,
										//enableRotation:true,
			
									});
						}
					}
				});
		drv.search('天安门', '天坛公园');

		//绑定事件
		$("run").onclick = function() {
			lushu.start();
		}
		$("stop").onclick = function() {
			lushu.stop();
		}
		$("pause").onclick = function() {
			lushu.pause();
		}
		$("hide").onclick = function() {
			lushu.hideInfoWindow();
		}
		$("show").onclick = function() {
			lushu.showInfoWindow();
		}
		function $(element) {
			return document.getElementById(element);
		}
		
	function searchData()	{		
		var stPosition=document.getElementById("stPosition").value;
		var endPosition=document.getElementById("endPosition").value;
		var carSpeed=document.getElementById("carSpeed").value;
		var carSp;
		if(stPosition==null ||stPosition==""){
			stPosition="天安门"
		}
		if(endPosition==null ||endPosition==""){
			endPosition="天坛公园"
		}
		if(carSpeed==null ||carSpeed==""){
			carSp=450
		}else if(carSpeed!=null && carSpeed!=""){
			carSp=parseInt(carSpeed)
		}
		
		var map = new BMap.Map('map_canvas');
		map.centerAndZoom(new BMap.Point(116.404, 39.915), 13);
		map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放

		var lushu;
		var distance;
		var output = "行车";
		
		var searchComplete = function (results){
			if (drv.getStatus() != BMAP_STATUS_SUCCESS){
				return ;
			}
			var plan = results.getPlan(0);
			output += "总路程为：" ;
			output += plan.getDistance(true);             //获取距离
			distance =plan.getDistance(true);
			
			var arrPois = results.getPlan(0).getRoute(0).getPath();
			map.addOverlay(new BMap.Polyline(arrPois, {
				strokeColor : '#111'
			}));
			map.setViewport(arrPois);

			lushu = new BMapLib.LuShu(
					map,
					arrPois,
					{
						defaultContent : "从"+stPosition+"到"+endPosition,
						speed : carSp,// 覆盖物移动速度，单位米/秒	
						autoView:true,//是否开启自动视野调整，如果开启那么路书在运动过程中会根据视野自动调整
						icon  : new BMap.Icon('images/car.png', new BMap.Size(52,26),{anchor : new BMap.Size(27, 13)}),
						enableRotation:true,//是否设置marker随着道路的走向进行旋转

					});
		}

		// 实例化一个驾车导航用来生成路线
		var drv = new BMap.DrivingRoute(map, {
			           renderOptions: {map: map},
			           onSearchComplete: searchComplete,
			           onPolylinesSet: function(){        
				       setTimeout(function(){
				    	   document.getElementById("routeDistance").value=output;
				    	   distance
				    	   var num= distance.replace(/[^0-9]/ig,"");
				    	   document.getElementById("routeTime").value=formatSeconds(num*1000/carSp);
				    	   
				    	   
				    	   },"1000");
		                }
		              });
		drv.search(stPosition, endPosition);

		//绑定事件
		$("run").onclick = function() {
			lushu.start();
		}
		$("stop").onclick = function() {
			lushu.stop();
		}
		$("pause").onclick = function() {
			lushu.pause();
		}
		$("hide").onclick = function() {
			lushu.hideInfoWindow();
		}
		$("show").onclick = function() {
			lushu.showInfoWindow();
		}
		function $(element) {
			return document.getElementById(element);
		}
	}	
		
	
    function formatSeconds(value) {
        var secondTime = parseInt(value);// 秒
        var minuteTime = 0;// 分
        var hourTime = 0;// 小时
        if(secondTime > 60) {//如果秒数大于60，将秒数转换成整数
            //获取分钟，除以60取整数，得到整数分钟
            minuteTime = parseInt(secondTime / 60);
            //获取秒数，秒数取佘，得到整数秒数
            secondTime = parseInt(secondTime % 60);
            //如果分钟大于60，将分钟转换成小时
            if(minuteTime > 60) {
                //获取小时，获取分钟除以60，得到整数小时
                hourTime = parseInt(minuteTime / 60);
                //获取小时后取佘的分，获取分钟除以60取佘的分
                minuteTime = parseInt(minuteTime % 60);
            }
        }
        var result = "" + parseInt(secondTime) + "秒";

        if(minuteTime > 0) {
            result = "" + parseInt(minuteTime) + "分" + result;
        }
        if(hourTime > 0) {
            result = "" + parseInt(hourTime) + "小时" + result;
        }
        return result;
    }	
	